package com.nuoyuan.wx.common.utils;

import org.apache.http.util.TextUtils;

public class StringUtils {

    public static boolean isEmpty(String str) {
        return str == null || str.length() == 0;
    }

    public static boolean isNotEmpty(String str) {
        return str != null && str.length() > 0;
    }

    /**
     *  * 字符串转换成为16进制(无需Unicode编码)
     *  * @param str
     *  * @return
     *  
     */
    public static String str2HexStr(String str) {
        char[] chars = "0123456789ABCDEF".toCharArray();
        StringBuilder sb = new StringBuilder("");
        byte[] bs = str.getBytes();
        int bit;
        for(int i = 0;i<bs.length;i++){
            bit = (bs[i] & 0x0f0) >> 4;
            sb.append(chars[bit]);
            bit = bs[i] & 0x0f;
            sb.append(chars[bit]);
        }
        return sb.toString().trim();
    }

    /**
     *
     * @param origin 掩码字符串
     * @param front     需要显示前几位
     * @param end       需要显示末几位
     * @return 处理完成的身份
     */
    public static String mask(String origin, int front, int end) {
        //计算*的数量
        int asteriskCount = origin.length() - (front + end);
        StringBuffer asteriskStr = new StringBuffer();
        for (int i = 0; i < asteriskCount; i++) {
            asteriskStr.append("*");
        }
        String regex = "(\\w{" + String.valueOf(front) + "})(\\w+)(\\w{" + String.valueOf(end) + "})";
        return origin.replaceAll(regex, "$1" + asteriskStr + "$3");
    }


}
